﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;

namespace MaymuseMS.Models {
    public class Order {
        public int OrderId { get; set; }
        [Required]
        [MaxLength(100)]
        public string Number { get; set; }
        public DateTime Date { get; set; }

        public int supplierId { get; set; }
        public virtual Supplier Supplier { get; set; }

        public int supplierUserId { get; set; }
        public virtual SupplierUser SupplierUser { get; set; }

        [MaxLength(100)]
        public string Demand { get; set; }
        [MaxLength(200)]
        public string Address { get; set; }
        [MaxLength(50)]
        public string Phone { get; set; }
        [MaxLength(50)]
        public string Fax { get; set; }
        [MaxLength(50)]
        public string DemandUser { get; set; }

        [MaxLength(1000)]
        public string Remark { get; set; }
        [MaxLength(1000)]
        public string ProductRequirements { get; set; }
        [MaxLength(1000)]
        public string PackagingRequirements { get; set; }
        //交货日期
        public DateTime? DeliveryDate { get; set; }
        //收货地址
        [MaxLength(200)]
        public string DeliveryAddress { get; set; }
        //收货人
        [MaxLength(100)]
        public string Consignee { get; set; }
        //收货人电话
        [MaxLength(100)]
        public string ConsigneeTelphone { get; set; }

        [MaxLength(1000)]
        public string Other { get; set; }

        //public int State { get; set; }
        public virtual IList<OrderItem> OrderItems { get; set; }

        //public static IDictionary<int, string> OrderState = new Dictionary<int, string> { 
        //    {1, "采购中"},
        //    {2, "已入库"}
        //};

        public decimal Total {
            get {
                if (OrderItems != null)
                    return OrderItems.Aggregate(0m, (t, o) => t + o.Price * (decimal)o.Count);
                return 0;
                //decimal itemPrice = 0;
                //foreach (var orderItem in OrderItems) {
                //    itemPrice = orderItem.Count * orderItem.Price;
                //}
                //return itemPrice;
            }
        }
    }
}